package com.zmn.oms.business.impl.work;

import com.zmn.oms.business.interfaces.work.OrderWorkRelationBService;
import com.zmn.oms.model.entity.work.OrderWorkRelation;
import com.zmn.oms.services.interfaces.work.OrderWorkRelationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * @author fubiao
 * @since 2022年03月23日 10:35
 */
@Service
public class OrderWorkRelationBServiceImpl implements OrderWorkRelationBService {

    @Autowired
    private OrderWorkRelationService workRelationService;

    @Override
    public Integer addOrderWorkRelation(OrderWorkRelation workRelation) {
        OrderWorkRelation orderWorkRelation = workRelationService.findOrderWorkRelationByOrderIdAndWorkId(workRelation.getOrderId(),
                workRelation.getWorkId(), workRelation.getType());
        if (Objects.isNull(orderWorkRelation)) {
            return workRelationService.insertOrderWorkRelation(workRelation);
        }
        return null;
    }

    @Override
    public Integer deleteOrderWorkRelationByWorkIdAndType(Long orderId, Long workId, Integer type) {
        return workRelationService.deleteOrderWorkRelationByWorkIdAndType(orderId, workId, type);
    }
}
